/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package Figures;

import java.awt.Point;
import java.util.ArrayList;

/**
 *
 * @author Macias
 */
public class Rouge extends Figures{

    int white;
    public Rouge(boolean isWh,Point loc){
        isWhite = isWh;
        location = loc;
        if(isWhite)white=1; else white=0;
        
    }


    @Override
    public ArrayList<Point> checkPossibleMoves(char [][] board) {
        ArrayList<Point> possibleMoves = new ArrayList();
        boolean dirN,dirS,dirE,dirW;
        dirN=dirS=dirE=dirW = true;
        int i= 1;
        while(dirN || dirS || dirE || dirW){         //we are searching possible moves in all directions if at least one is free we continue searching

            if(dirN){
                if((location.y-i)>=0 ){
                    if( board[location.x][location.y-i]=='0' ){    // location is empty
                        possibleMoves.add(new Point(location.x,location.y-i));
                    } else
                        if(board[location.x][location.y-i]>=(65+32*white) && board[location.x][location.y-i]<=(90+32*white)){ //we found oponents figure
                            possibleMoves.add(new Point(location.x,location.y-i));
                            dirN=false; //we cannot search further - this figure cannot jump over other figures
                        }

                    else    dirN=false;

                }   else dirN=false;
            }
            if(dirS){
                if((location.y+i)<=7 ){
                    if( board[location.x][location.y+i]=='0' ){    // location is empty
                        possibleMoves.add(new Point(location.x,location.y+i));
                    } else
                        if(board[location.x][location.y+i]>=(65+32*white) && board[location.x][location.y+i]<=(90+32*white)){ //we found oponents figure
                            possibleMoves.add(new Point(location.x,location.y+i));
                            dirS=false; //we cannot search further - this figure cannot jump over other figures
                        }

                    else    dirS=false;

                }   else dirS=false;
            }
            if(dirE){
                if((location.x+i)<=7){
                    if( board[location.x+i][location.y]=='0' ){    // location is empty
                        possibleMoves.add(new Point(location.x+i,location.y));
                    } else
                        if(board[location.x+i][location.y]>=(65+32*white) && board[location.x+i][location.y]<=(90+32*white)){ //we found oponents figure
                            possibleMoves.add(new Point(location.x+i,location.y));
                            dirE=false; //we cannot search further - this figure cannot jump over other figures
                        }

                    else    dirE=false;

                }   else dirE=false;
            }
            if(dirW){
                if((location.x-i)>=0){
                    if( board[location.x-i][location.y]=='0' ){    // location is empty
                        possibleMoves.add(new Point(location.x-i,location.y));
                    } else
                        if(board[location.x-i][location.y]>=(65+32*white) && board[location.x-i][location.y]<=(90+32*white)){ //we found oponents figure
                            possibleMoves.add(new Point(location.x-i,location.y));
                            dirW=false; //we cannot search further - this figure cannot jump over other figures
                        }

                    else    dirW=false;

                }   else dirW=false;
            }

            i++;
        }

        return possibleMoves;
    }
    @Override
    public int getType(){
        if(isWhite) return 82;
        else return 114;

    }
}
